package com.wf.atm.pojo;

import com.wf.atm.exception.BalanceNotEnoughException;

import java.io.Serializable;

/**
 * 储蓄账户
 * @author mpk
 *
 * @since 2024/6/3 18:13:30
 */
public class SavingAccount extends Account implements Serializable {

    private static final long serialVersionUID = 4930408196112890397L;

    public SavingAccount() {
    }

    @Override
    public Account withdraw(double balance) throws BalanceNotEnoughException {
        {
            if (this.getBalance() - balance < 0) {
                throw new BalanceNotEnoughException("余额不足!" + "剩余:" + this.getBalance());
            }

            this.setBalance(this.getBalance() - balance);

            return this;
        }
    }


    public SavingAccount(Long id, String password, String name, String personId,String address, String email) {
        super(id, password, name, personId, address,email);
    }

    @Override
    public String toString() {
        return "SavingAccount{} " + super.toString();
    }
}
